<?php
/**
 * Created by PhpStorm.
 * User: River
 * Email: river0428@gmail.com
 * Date: 2018/10/30
 * Time: 下午2:23
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Configure extends Model
{
    protected $table = 'configure';

    public $guarded = [];

    public static function getByKey($key)
    {
        $res = self::where('cfg_key', $key)->first();
        if ($res) {
            return $res->cfg_value;
        } else {
            return null;
        }
    }

    // 直充折扣
    public static function rechargeDiscount($def = 0.99)
    {
        return (float) self::getByKey('recharge_discount') ? : $def;
    }

    // 注册赠送优惠券
    public static function regCoupon($def = null)
    {
        $val = self::getByKey('reg_coupon');
        return explode(",", $val);
    }

    // 绑定油卡赠送优惠券
    public static function bindOilCardCoupon($def = [])
    {
        $val = self::getByKey('bind_oil_card_coupon');
        return explode(",", $val);
    }

    // 首次套餐充值赠送优惠券
    public static function rechargeCoupon($def = null)
    {
        $val = self::getByKey('recharge_coupon');
        return explode(",", $val);
    }

    // 注册赠送优惠券(给邀请人)
    public static function parentRegCoupon($def = null)
    {
        $val = self::getByKey('parent_reg_coupon');
        return explode(",", $val);
    }

    // 绑定油卡赠送优惠券(给邀请人)
    public static function parentBindOilCardCoupon($def = null)
    {
        $val = self::getByKey('parent_bind_oil_card_coupon');
        return explode(",", $val);
    }

    // 首次套餐充值赠送优惠券(给邀请人)
    public static function parentRechargeCoupon($def = null)
    {
        $val = self::getByKey('parent_recharge_coupon');
        return explode(",", $val);
    }

}